﻿using LuckDraw.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LuckDraw.Views
{
    /// <summary>
    /// UpdateRemovNumber.xaml 的交互逻辑
    /// </summary>
    public partial class UpdateRemovNumber : Window
    {
        public UpdateRemovNumber()
        {
            InitializeComponent();
            TbNumber.Text = PublicMethd.MaxWillNumber.ToString();
            RemoveNumber.Text = string.Join(",", PublicMethd.RemoveNumber);
        }

        private void save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(TbNumber.Text))
                    PublicMethd.MaxWillNumber = int.Parse(TbNumber.Text.Trim());
                INIHelper.WriteIniString("抽奖配置", "最大号码", PublicMethd.MaxWillNumber.ToString(), PublicMethd.ConfigFileName);
                if (!string.IsNullOrEmpty(RemoveNumber.Text))
                {
                    var data = RemoveNumber.Text.Trim().Split(',');
                    if (data != null)
                    {
                        PublicMethd.RemoveNumber = new List<int>();
                        for (int i = 0; i < data.Count(); i++)
                        {
                            string item = data[i].Trim();
                            if (!PublicMethd.RemoveNumber.Contains(int.Parse(item)))
                                PublicMethd.RemoveNumber.Add(int.Parse(item));
                        }
                        INIHelper.WriteIniString("抽奖配置", "去掉号码", string.Join(",", PublicMethd.RemoveNumber), PublicMethd.ConfigFileName);
                    }
                }
                this.DialogResult = true;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void canel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }
    }
}
